/*
 * AudioFactory.h
 *
 *  Created on: 09.08.2011
 *      Author: sili
 */

#ifndef AUDIOFACTORY_H_
#define AUDIOFACTORY_H_

#include "Controller.h"
#include "MaryClient.h"
#include <iostream>
#include <fstream>

#include <xine.h>
#include <xine/audio_out.h>

//#define DEBUG_DEVICE(format, args...) printf (format, ## args)
//#define nullptr 0

typedef struct xine_s             xine_t;
typedef struct xine_stream_s      xine_stream_t;
typedef struct xine_audio_port_s  xine_audio_port_t;
typedef struct xine_event_queue_s xine_event_queue_t;
typedef struct xine_video_port_s  xine_video_port_t;

class AudioFactory : public ActionListener , cThread{

private:

	string configDir;
	string audioCacheXmlFile;			// The property.xml file inside the configuration directory
	Controller * controller;
	map<string,string> audioCache;

	string mrl;

	MaryClient * maryClient;

	vector<AALAction *> audioActions;

	xine_t             *xine_;
	xine_audio_port_t  *aoPort_;
	xine_video_port_t  *voPort_;
	xine_stream_t      *stream_;
	xine_event_queue_t *eventQueue_;

	virtual void serializeCacheFile();
	virtual void deSerializeCacheFile();
	const char * getAudioCacheFilename(const char * _text);
	void saveCacheFile(const char * _key, const char * _value);
	void deleteCacheFile(const char * _key);

protected:
	virtual void Action(void);

public:
	AudioFactory(Controller * controller, const char * _configDir);
	virtual ~AudioFactory();

	/**
	 * OVERWRITE
	 * I'm an ActionListener
	 */
	void doAction(AALAction * _action);
	void doMainSavedAction();
	void discardAction(AALAction * _action);
};

#endif /* AUDIOFACTORY_H_ */
